$( document ).bind( 'mobileinit', function(){
  $.mobile.loader.prototype.options.text = "loading";
  $.mobile.loader.prototype.options.textVisible = false;
  $.mobile.loader.prototype.options.theme = "a";
  $.mobile.loader.prototype.options.html = "";
  
  
});



$('div#top').live('pageshow',function(event){
    $.mobile.loading('show',{text:'loading wait...',textVisible:true,theme:'a'});
    var url = 'https://graph.facebook.com/funngobigg/links?access_token=AAACFjHGm99ABAI1e0UGU1FeZC3ZAZBrbXcMR0J0NFMskqFNEIZA99ZC8fPNSo6lZAlrh0LeAxrDkZBAElHL9ibiwVS6Y4IMXcd9mjSZBArexUgZDZD'
       $.getJSON(url,{
        format:'json',
       },function(json) {
          var len = json.data.length;
          var html = '<table>';
          for(i=0;i<len;i++){
            html = html + themeFb(json.data[i]);
          }
		  html += '</table><div style="width:100%; height:60px">&nbsp;</div>';
          //A little animation once fetched
          $('#topvcontent').animate({opacity:0}, 500, function(){
              $('#topvcontent').html(html);
          });
          $('#topvcontent').animate({opacity:1}, 500);
          $.mobile.loading('hide');
      });
});



var themeFb = function(fbfeed){
  var html='';
  if(typeof fbfeed.picture != 'undefined' && typeof fbfeed.message != 'undefined'){
    html = '<tr >';
      html += "<td class='tcell timg' >";
        html += "<div class='img_frame'><img src='"+fbfeed.picture+"' /></div>";
      html += "</td>";
      html += "<td class='tcell'>";
        html += fbfeed.message;
        //html += "<label style='float:right; font-size:10px'>"+fbfeed.created_time+"</label>";
      html += "</td>";
    html += '</tr>';
  }
  return html
}

$('div#cat').live('pageshow',function(event){
});

$('div#home').live('pageshow',function(event){
    $.mobile.loading('show',{text:'loading wait...',textVisible:true,theme:'a'});
    var url = 'https://graph.facebook.com/uGoBigg/links?access_token=AAACFjHGm99ABAI1e0UGU1FeZC3ZAZBrbXcMR0J0NFMskqFNEIZA99ZC8fPNSo6lZAlrh0LeAxrDkZBAElHL9ibiwVS6Y4IMXcd9mjSZBArexUgZDZD'
       $.getJSON(url,{
        format:'json',
       },function(json) {
          var len = json.data.length;
          var html = '<table>';
          for(i=0;i<len;i++){
            html = html + themeFb(json.data[i]);
          }
		  html += '</table><div style="width:100%; height:50px">&nbsp;</div>';
          //A little animation once fetched
          $('#homevcontent').animate({opacity:0},500, function(){
              $('#homevcontent').html(html);
          });
          $('#homevcontent').animate({opacity:1}, 500);
          $.mobile.loading('hide');
      });
    
});


$('div#viewcat').live('pageshow',function(event){
    $.mobile.loading('show',{text:'loading wait...',textVisible:true,theme:'a'});
    var catToShow = localStorage.getItem('catToShow');
    var url = 'https://graph.facebook.com/search?q='+catToShow+'&type=post&limit=70&access_token=AAACFjHGm99ABAI1e0UGU1FeZC3ZAZBrbXcMR0J0NFMskqFNEIZA99ZC8fPNSo6lZAlrh0LeAxrDkZBAElHL9ibiwVS6Y4IMXcd9mjSZBArexUgZDZD'
    $.getJSON(url,{
     format:'json',
    },function(json) {
       var len = json.data.length;
       var html = catToShow+'<table>';
       for(i=0;i<len;i++){
         if(json.data[i].type=='link')
         html = html + themeFb(json.data[i]);
       }
       html += '</table><div style="width:100%; height:50px">&nbsp;</div>';
       //A little animation once fetched
       $('#viewcatvcontent').animate({opacity:0}, 500, function(){
           $('#viewcatvcontent').html(html);
       });
       $('#viewcatvcontent').animate({opacity:1}, 500);
       $.mobile.loading('hide');
   });
});


function getFeed(cat){
    $.mobile.loading('show',{text:'loading wait...',textVisible:true,theme:'a'});
    $.ajax({
      url: 'http://localhost/test2/feed/feed.php?what='+cat,
      success: function(feed) {
         $(".content").html(feed);
         $.mobile.loading( 'hide');
      }
   });

  
}
